package com.shuangzh.brief.rpc;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * 请求对象， 携带 调用方法名和请求参数
 * @author shuangzh
 *
 */
public class RequestObject implements Serializable {

	private static final long serialVersionUID = 3434076251765777925L;
	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	/**
	 * 请求唯一id；
	 */
	private long id;
	/**
	 * 调用的函数名
	 */
	private String methodName;
	/**
	 * 请求参数
	 */
	private Object[] args;
	
	/**
	 * 调用方法的参数类型
	 */
	private Class[] parameterTypes;
	

	public Class[] getParameterTypes() {
		return parameterTypes;
	}

	public void setParameterTypes(Class[] parameterTypes) {
		this.parameterTypes = parameterTypes;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public Object[] getArgs() {
		return args;
	}

	public void setArgs(Object[] args) {
		this.args = args;
	}

	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		
		RequestObject req = new RequestObject();
		req.setId(100);
		req.setArgs(null);
		req.setMethodName("haha");
		
		ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("obj.out"));
		out.writeObject(req);
		out.close();
		
		ObjectInputStream in=new ObjectInputStream(new FileInputStream("obj.out"));
		RequestObject req2 = (RequestObject) in.readObject();
		
		System.out.println(new ReflectionToStringBuilder(req2).build());
		
	}
}
